<?php

namespace App\Http\Controllers\Admin;

use App\Models\Admin\Collection\CollectionResume;
use App\Models\Admin\Collection\CollectionResumeCertificate;
use App\Models\Admin\Collection\CollectionResumeCheck;
use App\Models\Admin\Collection\CollectionResumeEducation;
use App\Models\Admin\Collection\CollectionResumeLanguageSkill;
use App\Models\Admin\Collection\CollectionResumeOther;
use App\Models\Admin\Collection\CollectionResumeProjectExp;
use App\Models\Admin\Collection\CollectionResumeSkill;
use App\Models\Admin\Collection\CollectionResumeWorkExp;
use App\Models\Admin\Collection\CollectionTrackResume;
use App\Models\Common\CollTown;
use App\Models\Common\CollArea;
use App\Models\Common\CollOption;
use App\Models\Common\CollPosition;
use App\Models\Common\CollTwoOption;
use App\Models\Personal\PersonalUser;
use App\Models\Personal\Resume;
use App\Models\Personal\ResumeCertificate;
use App\Models\Personal\ResumeEducationExp;
use App\Models\Personal\ResumeLanguageSkill;
use App\Models\Personal\ResumeOther;
use App\Models\Personal\ResumeProjectExp;
use App\Models\Personal\ResumeSkill;
use App\Models\Personal\ResumeWorkExp;
use Illuminate\Http\Request;
use App\Http\Requests\Admin\Collection\resumeBasicRequest;
use App\Http\Requests\Admin\Collection\resumeObjectiveRequest;
use App\Http\Requests\Admin\Collection\addWorkExpRequest;
use App\Http\Requests\Admin\Collection\modWorkExpRequest;
use App\Http\Requests\Admin\Collection\addEducationExpRequest;
use App\Http\Requests\Admin\Collection\modEducationExpRequest;
use App\Http\Requests\Admin\Collection\modProjectExpRequest;
use App\Http\Requests\Admin\Collection\addProjectExpRequest;
use App\Http\Requests\Admin\Collection\addOtherRequest;
use App\Http\Requests\Admin\Collection\modOtherRequest;
use Illuminate\Support\Facades\DB;
use Style, CustomPassword, Sms, Site;

class CollectionResumeController extends CommonController{

    /**
     * 跳过该简历
     * @param Request $request
     * @param $id
     */
    public function resumeJump(Request $request, $resume_id){
        $page = !empty($request->page) ? $request->page : '1';
        $result = CollectionResume::where('id', $resume_id)->update(['show_type' => 2]);
        if($result){
            return redirect('admin/resume_list?page=' . $page);
        }else{
            return redirect('admin/resume_list')->with('error', '该简历不存在，或者已经添加到正式库！');
        }
    }

    /**
     * 下一条数据内容
     * @param Request $request
     * @param $resume_id
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function resumeNext(Request $request, $resume_id){
        $collectionResume = CollectionResume::where('id', '<', $resume_id)->where('show_type', '1')->orderBy('id', 'desc')->first(['id']);
        if(!empty($collectionResume)){
            return redirect('admin/resume_tmp_manage?resume_id=' . $collectionResume->id);
        }else{
            return back()->with('last', '1');//最后一条
        }
    }
    /**
     * 跳过该简历
     * @param Request $request
     * @param $resume_id
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function jumpResume(Request $request){
        $resume_id = !empty($request->id) ? $request->id : '';
        $result = CollectionResumeCheck::where('resume_id',$resume_id)->delete();
        if($result){
            return response()->json(['status' => 0, 'msg' => '跳过该简历成功！']);
        }else{
            return response()->json(['status' => 1,'msg' => '跳过该简历失败，请稍后重试！']);
        }
    }

    /**
     * 手动添加临时采集简历
     * @param Request $request
     * @return mixed
     */
    public function resumeTmpManage(Request $request){
        $page = !empty($request->page) ? $request->page : '1';
        $resume = CollectionResume::where('id', $request->resume_id)->where('show_type', '1')->first();
        if(!empty($resume)){
            //---基本信息--------------------------------------------------------------------------------------------------------------------
            $resumeArr = $resume->toArray();
            //基本信息json
            //工地地区
            $jobarea1 = (strlen($resumeArr['jobarea1']) == 8) ? CollTown::getTownName($resumeArr['jobarea1']) : CollArea::getAreaName($resumeArr['jobarea1']);
            $jobarea2 = (strlen($resumeArr['jobarea2']) == 8) ? CollTown::getTownName($resumeArr['jobarea2']) : CollArea::getAreaName($resumeArr['jobarea2']);
            $jobarea3 = (strlen($resumeArr['jobarea3']) == 8) ? CollTown::getTownName($resumeArr['jobarea3']) : CollArea::getAreaName($resumeArr['jobarea3']);
            $jobarea4 = (strlen($resumeArr['jobarea4']) == 8) ? CollTown::getTownName($resumeArr['jobarea4']) : CollArea::getAreaName($resumeArr['jobarea4']);
            $jobarea5 = (strlen($resumeArr['jobarea5']) == 8) ? CollTown::getTownName($resumeArr['jobarea5']) : CollArea::getAreaName($resumeArr['jobarea5']);
            $jobarea = $jobarea1 . ',' . $jobarea2 . ',' . $jobarea3 . ',' . $jobarea4 . ',' . $jobarea5;
            //工地岗位
            $jobsort1 = ($resumeArr['jobsort1']) ? CollPosition::getPosName($resumeArr['jobsort1']) : '';
            $jobsort2 = ($resumeArr['jobsort2']) ? CollPosition::getPosName($resumeArr['jobsort2']) : '';
            $jobsort3 = ($resumeArr['jobsort3']) ? CollPosition::getPosName($resumeArr['jobsort3']) : '';
            $jobsort4 = ($resumeArr['jobsort4']) ? CollPosition::getPosName($resumeArr['jobsort4']) : '';
            $jobsort5 = ($resumeArr['jobsort5']) ? CollPosition::getPosName($resumeArr['jobsort5']) : '';
            $jobsort = $jobsort1 . ',' . $jobsort2 . ',' . $jobsort3 . ',' . $jobsort4 . ',' . $jobsort5;
            $resumeArr2 = array(
                'avatar' => asset('default/images/personal/headPortrait.jpg'),
                'job_status' => !empty($resumeArr['job_status']) ? CollOption::getOptionName($resumeArr['job_status'], 'job_status') : '',
                'education' => !empty($resumeArr['education']) ? CollOption::getOptionName($resumeArr['education'], 'education') : '未填写',
                'work_year' => !empty($resumeArr['work_year']) ? CollOption::getOptionName($resumeArr['work_year'], 'work_year') : "无经验",
                'homeaddress' => !empty($resumeArr['homeaddress']) ? CollArea::getAreaAddress($resumeArr['homeaddress']) : '未填写',
                'expectedsalary' => ($resumeArr['expectedsalary']) ? CollOption::getOptionName($resumeArr['expectedsalary'], 'expectedsalary') . '元/月' : '面议',
                'jobarea' => msubstr(trim($jobarea, ','), 0, 22),
                'jobsort' => msubstr(trim($jobsort, ','), 0, 22),
                'sex' => ($resumeArr['sex'] == '1') ? '男' : (($resumeArr['sex'] == '2') ? '女' : '未填写'),
                'birthday' => ($resumeArr['birthday'] != '0000-00-00') ? birthday($resumeArr['birthday']) : '0',
                'census' => !empty($resumeArr['census']) ? CollArea::getAreaAddress($resumeArr['census']) : '未填写',
                'marital' => !empty($resumeArr['marital']) ? CollOption::getOptionName($resumeArr['marital'], 'marital') : '未填写',
                'height' => !empty($resumeArr['height']) ? $resumeArr['height'] . 'cm' : '未填写',
                'phoneAddress' => !empty($resumeArr['homeaddress']) ? CollArea::getAreaName(substr($resumeArr['homeaddress'], 0, 2) . '0000') : '未知',
                'mobile' => !empty($resumeArr['mobile']) ? $resumeArr['mobile'] : '未填写',
                'email' => !empty($resumeArr['email']) ? $resumeArr['email'] : '未填写'
            );
            $reArr = array_merge($resumeArr, $resumeArr2);
            $resumeJson = json_encode($resumeArr);

            //---求职意向--------------------------------------------------------------------------------------------------------------------
            $jobarea = $jobarea1 . '+' . $jobarea2 . '+' . $jobarea3 . '+' . $jobarea4 . '+' . $jobarea5;
            $jobsort = $jobsort1 . '+' . $jobsort2 . '+' . $jobsort3 . '+' . $jobsort4 . '+' . $jobsort5;
            $objectiveArr = array(
                'intentionjobs' => $resumeArr['intentionjobs'],
                'isexpectedsalary' => $resumeArr['isexpectedsalary'],
                'jobarea1' => $resumeArr['jobarea1'],
                'jobarea2' => $resumeArr['jobarea2'],
                'jobarea3' => $resumeArr['jobarea3'],
                'jobarea4' => $resumeArr['jobarea4'],
                'jobarea5' => $resumeArr['jobarea5'],
                'jobarea' => trim($jobarea, '+'),
                'jobsort1' => $resumeArr['jobsort1'],
                'jobsort2' => $resumeArr['jobsort2'],
                'jobsort3' => $resumeArr['jobsort3'],
                'jobsort4' => $resumeArr['jobsort4'],
                'jobsort5' => $resumeArr['jobsort5'],
                'jobsort' => trim($jobsort, '+'),
                'expectedsalary' => ($resumeArr['expectedsalary'] == '面议') ? '面议' : $resumeArr['expectedsalary'],
            );
            $objectiveJson = json_encode($objectiveArr);

            //---自我评价--------------------------------------------------------------------------------------------------------------------
            $objectiveArr = array(
                'introduction' => $resumeArr['introduction']
            );
            $evaluationJson = json_encode($objectiveArr);

            //---工作经历--------------------------------------------------------------------------------------------------------------------
            $workExp = CollectionResumeWorkExp::where('resume_id', $resume->id)->orderBy('updatetime', 'desc')->get()->toArray();
            $workExpArr = [];
            if(count($workExp) > 0){
                foreach($workExp as $v){
                    $arr = array(
                        'industry' => (!empty($v['industry'])) ? CollOption::getOptionName($v['industry'], 'industry') : "",
                        'comkind' => (!empty($v['comkind'])) ? CollOption::getOptionName($v['comkind'], 'comkind') : "",
                        'scale' => (!empty($v['scale'])) ? CollOption::getOptionName($v['scale'], 'employee_num') : "",
                        'starttime' => substr($v['starttime'], 0, 7),
                        'endtime' => ($v['endtime'] == '0000-00-00') ? '至今' : substr($v['endtime'], 0, 7)
                    );
                    $workExpArr[] = array_merge($v, $arr);
                }
            }
            //---教育经历------------------------------------------------------------------------------------------------------------------------------------------------------
            $eduExp = CollectionResumeEducation::where('resume_id', $resume->id)->orderBy('updatetime', 'desc')->get()->toArray();

            $eduExpArr = [];
            if(count($eduExp) > 0){
                foreach($eduExp as $v){
                    $arr = array(
                        'education' => CollOption::getOptionName($v['education'], 'education'),
                        'starttime' => substr($v['starttime'], 0, 7),
                        'endtime' => ($v['endtime'] == '0000-00-00') ? '至今' : substr($v['endtime'], 0, 7)
                    );
                    $eduExpArr[] = array_merge($v, $arr);
                }
            }
            //---项目经验-------------------------------------------------------------------------------------------------------------------------------------------------------
            $projectExp = CollectionResumeProjectExp::where('resume_id', $resume->id)->orderBy('updatetime', 'desc')->get()->toArray();
            $projectExpArr = [];
            if(count($projectExp) > 0){
                foreach($projectExp as $v){
                    $arr = array(
                        'starttime' => substr($v['starttime'], 0, 7),
                        'post' => !empty($v['post']) ? $v['post'] : '无',
                        'endtime' => ($v['endtime'] == '0000-00-00') ? '至今' : substr($v['endtime'], 0, 7)
                    );
                    $projectExpArr[] = array_merge($v, $arr);
                }
            }
            //---语言能力-------------------------------------------------------------------------------------------------------------------------------------------------------
            $language = CollectionResumeLanguageSkill::where('resume_id', $resume->id)->orderBy('id')->get()->toArray();
            $languageArr = [];
            if(count($language) > 0){
                foreach($language as $v){
                    $arr = array(
                        'language' => CollOption::getOptionName($v['language'], 'language'),
                        'degree' => CollOption::getOptionName($v['degree'], 'degree'),
                        'level' => CollTwoOption::getTwoOptionName($v['level'], 'language')
                    );
                    $languageArr[] = array_merge($v, $arr);
                }
            }
            $languageJson = json_encode($language);
            //---技能专长-------------------------------------------------------------------------------------------------------------------------------------------------------
            $skill = CollectionResumeSkill::where('resume_id', $resume->id)->orderBy('id')->get()->toArray();
            $skillArr = [];
            if(count($skill) > 0){
                foreach($skill as $v){
                    $arr = array(
                        'degree' => CollOption::getOptionName($v['degree'], 'degree')
                    );
                    $skillArr[] = array_merge($v, $arr);
                }
            }
            $skillJson = json_encode($skill);
            //---证书-------------------------------------------------------------------------------------------------------------------------------------------------------
            $certificate = CollectionResumeCertificate::where('resume_id', $resume->id)->orderBy('id')->get()->toArray();
            $certificateArr = [];
            if(count($certificate) > 0){
                foreach($certificate as $v){
                    $arr = array(
                        'gettime' => substr($v['gettime'], 0, 4)
                    );
                    $certificateArr[] = array_merge($v, $arr);
                }
            }
            $certificateJson = json_encode($certificate);
            //---其它信息-------------------------------------------------------------------------------------------------------------------------------------------------------
            $otherArr = CollectionResumeOther::where('resume_id', $resume->id)->orderBy('updatetime', 'desc')->get()->toArray();
            $otherJson = json_encode($otherArr);

            //来源地址
            $source = CollectionTrackResume::where('resume_id', $request->resume_id)->first(['source'])->source;
            return Style::view('admin.collection.resumeTmpManage', compact('reArr', 'resumeJson', 'objectiveJson', 'evaluationJson', 'workExpArr', 'eduExpArr'
                , 'projectExpArr', 'languageArr', 'languageJson', 'skillArr', 'skillJson', 'certificateArr', 'certificateJson', 'otherArr', 'otherJson', 'source', 'page'));
        }else{
            $err_msg = '对不起，该简历不存在，或者已经添加到正式库.';
            return Style::view('errors.collection', compact('err_msg'));
        }
    }

    /**
     * 更新基本信息
     * @param  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function resumeBasic(resumeBasicRequest $request){
        //登录信息
        $input = $request->only(['name', 'sex', 'birthday', 'work_year', 'homeaddress', 'job_status', 'education', 'mobile', 'qq',
            'email', 'address', 'census', 'marital', 'height', 'place_name', 'longitude', 'latitude']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        $input['show_type'] = 1;//设置简历状态
        CollectionResume::where('id', $request->resume_id)->update($input);

        //获取更新后的数据
        $resumeArr = CollectionResume::where('id', $request->resume_id)->first()->toArray();
        //工地地区
        $jobarea1 = (strlen($resumeArr['jobarea1']) == 8) ? CollTown::getTownName($resumeArr['jobarea1']) : CollArea::getAreaName($resumeArr['jobarea1']);
        $jobarea2 = (strlen($resumeArr['jobarea2']) == 8) ? CollTown::getTownName($resumeArr['jobarea2']) : CollArea::getAreaName($resumeArr['jobarea2']);
        $jobarea3 = (strlen($resumeArr['jobarea3']) == 8) ? CollTown::getTownName($resumeArr['jobarea3']) : CollArea::getAreaName($resumeArr['jobarea3']);
        $jobarea4 = (strlen($resumeArr['jobarea4']) == 8) ? CollTown::getTownName($resumeArr['jobarea4']) : CollArea::getAreaName($resumeArr['jobarea4']);
        $jobarea5 = (strlen($resumeArr['jobarea5']) == 8) ? CollTown::getTownName($resumeArr['jobarea5']) : CollArea::getAreaName($resumeArr['jobarea5']);
        $jobarea = $jobarea1 . ',' . $jobarea2 . ',' . $jobarea3 . ',' . $jobarea4 . ',' . $jobarea5;

        $resumeArr2 = array(
            'avatar' => asset('default/images/personal/headPortrait.jpg'),
            'job_status' => !empty($resumeArr['job_status']) ? CollOption::getOptionName($resumeArr['job_status'], 'job_status') : '',
            'education' => !empty($resumeArr['education']) ? CollOption::getOptionName($resumeArr['education'], 'education') : '未填写',
            'work_year' => !empty($resumeArr['work_year']) ? CollOption::getOptionName($resumeArr['work_year'], 'work_year') : "无经验",
            'homeaddress' => !empty($resumeArr['homeaddress']) ? CollArea::getAreaAddress($resumeArr['homeaddress']) : '未填写',
            'jobarea' => msubstr(trim($jobarea, ','), 0, 22),
            'sex' => ($resumeArr['sex'] == '1') ? '男' : (($resumeArr['sex'] == '2') ? '女' : '未填写'),
            'birthday' => ($resumeArr['birthday'] != '0000-00-00') ? birthday($resumeArr['birthday']) : '0',
            'census' => !empty($resumeArr['census']) ? CollArea::getAreaAddress($resumeArr['census']) : '未填写',
            'marital' => !empty($resumeArr['marital']) ? CollOption::getOptionName($resumeArr['marital'], 'marital') : '未填写',
            'height' => !empty($resumeArr['height']) ? $resumeArr['height'] . 'cm' : '未填写',
            'phoneAddress' => !empty($resumeArr['homeaddress']) ? CollArea::getAreaName(substr($resumeArr['homeaddress'], 0, 2) . '0000') : '未知',
            'mobile' => !empty($resumeArr['mobile']) ? $resumeArr['mobile'] : '未填写',
            'email' => !empty($resumeArr['email']) ? $resumeArr['email'] : '未填写'
        );
        $reArr = array_merge($resumeArr, $resumeArr2);
        $arrMerge['one'] = $resumeArr;
        $arrMerge['two'] = $reArr;
        return response()->json($arrMerge);
    }

    /**
     * 更新求职意向
     * @param resumeObjectiveRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function resumeObjective(resumeObjectiveRequest $request){
        $input = $request->only(['intentionjobs', 'jobarea1', 'jobarea2', 'jobarea3', 'jobarea4', 'jobarea5',
            'jobsort1', 'jobsort2', 'jobsort3', 'jobsort4', 'jobsort5', 'expectedsalary', 'isexpectedsalary']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        CollectionResume::where('id', $request->resume_id)->update($input);
        $resumeArr = CollectionResume::where('id', $request->resume_id)->first()->toArray();
        //工地地区
        $jobarea1 = (strlen($resumeArr['jobarea1']) == 8) ? CollTown::getTownName($resumeArr['jobarea1']) : CollArea::getAreaName($resumeArr['jobarea1']);
        $jobarea2 = (strlen($resumeArr['jobarea2']) == 8) ? CollTown::getTownName($resumeArr['jobarea2']) : CollArea::getAreaName($resumeArr['jobarea2']);
        $jobarea3 = (strlen($resumeArr['jobarea3']) == 8) ? CollTown::getTownName($resumeArr['jobarea3']) : CollArea::getAreaName($resumeArr['jobarea3']);
        $jobarea4 = (strlen($resumeArr['jobarea4']) == 8) ? CollTown::getTownName($resumeArr['jobarea4']) : CollArea::getAreaName($resumeArr['jobarea4']);
        $jobarea5 = (strlen($resumeArr['jobarea5']) == 8) ? CollTown::getTownName($resumeArr['jobarea5']) : CollArea::getAreaName($resumeArr['jobarea5']);
        $jobarea = $jobarea1 . ',' . $jobarea2 . ',' . $jobarea3 . ',' . $jobarea4 . ',' . $jobarea5;
        //工地岗位
        $jobsort1 = ($resumeArr['jobsort1']) ? CollPosition::getPosName($resumeArr['jobsort1']) : '';
        $jobsort2 = ($resumeArr['jobsort2']) ? CollPosition::getPosName($resumeArr['jobsort2']) : '';
        $jobsort3 = ($resumeArr['jobsort3']) ? CollPosition::getPosName($resumeArr['jobsort3']) : '';
        $jobsort4 = ($resumeArr['jobsort4']) ? CollPosition::getPosName($resumeArr['jobsort4']) : '';
        $jobsort5 = ($resumeArr['jobsort5']) ? CollPosition::getPosName($resumeArr['jobsort5']) : '';
        $jobsort = $jobsort1 . ',' . $jobsort2 . ',' . $jobsort3 . ',' . $jobsort4 . ',' . $jobsort5;

        $objectiveArr['arr'] = array(
            'intentionjobs' => $resumeArr['intentionjobs'],
            'isexpectedsalary' => $resumeArr['isexpectedsalary'],
            'jobarea' => msubstr(trim($jobarea, ','), 0, 22),
            'jobsort' => msubstr(trim($jobsort, ','), 0, 22),
            'expectedsalary' => ($resumeArr['expectedsalary']) ? CollOption::getOptionName($resumeArr['expectedsalary'], 'expectedsalary') . '元/月' : '面议',
        );

        $jobarea = $jobarea1 . '+' . $jobarea2 . '+' . $jobarea3 . '+' . $jobarea4 . '+' . $jobarea5;
        $jobsort = $jobsort1 . '+' . $jobsort2 . '+' . $jobsort3 . '+' . $jobsort4 . '+' . $jobsort5;
        $objectiveArr['json'] = array(
            'intentionjobs' => $resumeArr['intentionjobs'],
            'isexpectedsalary' => $resumeArr['isexpectedsalary'],
            'jobarea1' => $resumeArr['jobarea1'],
            'jobarea2' => $resumeArr['jobarea2'],
            'jobarea3' => $resumeArr['jobarea3'],
            'jobarea4' => $resumeArr['jobarea4'],
            'jobarea5' => $resumeArr['jobarea5'],
            'jobarea' => trim($jobarea, '+'),
            'jobsort1' => $resumeArr['jobsort1'],
            'jobsort2' => $resumeArr['jobsort2'],
            'jobsort3' => $resumeArr['jobsort3'],
            'jobsort4' => $resumeArr['jobsort4'],
            'jobsort5' => $resumeArr['jobsort5'],
            'jobsort' => trim($jobsort, '+'),
            'expectedsalary' => ($resumeArr['expectedsalary']) ? CollOption::getOptionName($resumeArr['expectedsalary'], 'expectedsalary') : '',
        );
        return response()->json($objectiveArr);
    }

    /**
     * 更新自我评价
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function resumeEvaluation(Request $request){
        $input = $request->only(['introduction']);
        $input['introduction'] = trim($request->introduction);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        CollectionResume::where('id', $request->resume_id)->update($input);
        $resumeArr = CollectionResume::where('id', $request->resume_id)->first()->toArray();
        $evaluationArr['json'] = array(
            'introduction' => $resumeArr['introduction']
        );
        return response()->json($evaluationArr);
    }

    //工作经历------------------------------------------------------------------------------------------------------------------
    /**
     * 工作经历
     * @param addWorkExpRequest $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
     */
    public function addWorkExp(addWorkExpRequest $request){
        $input = $request->only(['company', 'resume_id', 'industry', 'comkind', 'scale', 'starttime', 'endtime', 'post', 'content']);
        //获取用户信息ID
        $input['addtime'] = date('Y-m-d H:i:s', time());
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        //返回插入的最后ID
        $id = CollectionResumeWorkExp::insertGetId($input);

        //获取插入后的数据
        $workExpArr = CollectionResumeWorkExp::where('id', $id)->first()->toArray();
        $workExpArr2 = array(
            'industry' => (!empty($workExpArr['industry'])) ? CollOption::getOptionName($workExpArr['industry'], 'industry') : "",
            'comkind' => (!empty($workExpArr['comkind'])) ? CollOption::getOptionName($workExpArr['comkind'], 'comkind') : "",
            'scale' => (!empty($workExpArr['scale'])) ? CollOption::getOptionName($workExpArr['scale'], 'employee_num') : "",
            'starttime' => substr($workExpArr['starttime'], 0, 7),
            'endtime' => ($workExpArr['endtime'] == '0000-00-00') ? '至今' : substr($workExpArr['endtime'], 0, 7)
        );
        $workExp['arr'] = array_merge($workExpArr, $workExpArr2);
        $workExp['json'] = $workExpArr;
        return response()->json($workExp);
    }

    /**
     * 修改工作经历
     * @param modWorkExpRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function modWorkExp(modWorkExpRequest $request){
        $input = $request->only(['company', 'industry', 'comkind', 'scale', 'starttime', 'endtime', 'post', 'content']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        CollectionResumeWorkExp::where('id', $request->id)->update($input);

        //获取修改后的数据
        $workExpArr = CollectionResumeWorkExp::where('id', $request->id)->first()->toArray();
        $workExpArr2 = array(
            'industry' => (!empty($workExpArr['industry'])) ? CollOption::getOptionName($workExpArr['industry'], 'industry') : "",
            'comkind' => (!empty($workExpArr['comkind'])) ? CollOption::getOptionName($workExpArr['comkind'], 'comkind') : "",
            'scale' => (!empty($workExpArr['scale'])) ? CollOption::getOptionName($workExpArr['scale'], 'employee_num') : "",
            'starttime' => substr($workExpArr['starttime'], 0, 7),
            'endtime' => ($workExpArr['endtime'] == '0000-00-00') ? '至今' : substr($workExpArr['endtime'], 0, 7)
        );

        $workExp['arr'] = array_merge($workExpArr, $workExpArr2);
        $workExp['json'] = $workExpArr;
        return response()->json($workExp);
    }

    /**
     *编辑工作经历
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function editWorkExp(Request $request){
        $workExpArr = CollectionResumeWorkExp::where('id', $request->id)->first()->toArray();
        return response()->json($workExpArr);
    }

    /**
     * 删除工作经历
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delWorkExp(Request $request){
        $result = CollectionResumeWorkExp::where('id', $request->id)->delete();
        if($result){
            return response()->json(['status' => 0, 'msg' => '删除工作经历成功！']);
        }else{
            return response()->json(['status' => 1, 'msg' => '删除工作经历失败，请稍后重试！']);
        }
    }

    //教育经历------------------------------------------------------------------------------------------------------------------
    /**
     * 教育经历
     * @param addEducationExpRequest $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
     */
    public function addEduExp(addEducationExpRequest $request){
        if($request->edu_type == '1')
            $input = $request->only(['resume_id', 'school', 'starttime', 'endtime', 'speciality', 'education', 'type', 'edu_type', 'description']);
        else
            $input = $request->only(['resume_id', 'school', 'starttime', 'endtime', 'speciality', 'type', 'edu_type', 'description']);

        //获取用户信息ID
        $input['type'] = empty($request->type) ? '0' : $request->type;
        $input['addtime'] = date('Y-m-d H:i:s', time());
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        //返回插入的最后ID
        $id = CollectionResumeEducation::insertGetId($input);

        //获取插入后的数据
        $eduExpArr = CollectionResumeEducation::where('id', $id)->first()->toArray();
        $eduExpArr2 = array(
            'education' => CollOption::getOptionName($eduExpArr['education'], 'education'),
            'starttime' => substr($eduExpArr['starttime'], 0, 7),
            'endtime' => ($eduExpArr['endtime'] == '0000-00-00') ? '至今' : substr($eduExpArr['endtime'], 0, 7)
        );

        $eduExp['arr'] = array_merge($eduExpArr, $eduExpArr2);
        $eduExp['json'] = $eduExpArr;
        return response()->json($eduExp);
    }

    /**
     * 修改教育经历
     * @param modEducationExpRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function modEduExp(modEducationExpRequest $request){
        if($request->edu_type == '1')
            $input = $request->only(['resume_id', 'school', 'starttime', 'endtime', 'speciality', 'education', 'type', 'edu_type', 'description']);
        else
            $input = $request->only(['resume_id', 'school', 'starttime', 'endtime', 'speciality', 'type', 'edu_type', 'description']);

        $input['type'] = empty($request->type) ? '0' : $request->type;
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        CollectionResumeEducation::where('id', $request->id)->update($input);

        //获取插入后的数据
        $eduExpArr = CollectionResumeEducation::where('id', $request->id)->first()->toArray();
        $eduExpArr2 = array(
            'education' => CollOption::getOptionName($eduExpArr['education'], 'education'),
            'starttime' => substr($eduExpArr['starttime'], 0, 7),
            'endtime' => ($eduExpArr['endtime'] == '0000-00-00') ? '至今' : substr($eduExpArr['endtime'], 0, 7)
        );

        $eduExp['arr'] = array_merge($eduExpArr, $eduExpArr2);
        $eduExp['json'] = $eduExpArr;
        return response()->json($eduExp);
    }

    /**
     * 编辑教育经历
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function editEduExp(Request $request){
        $eduExpArr = CollectionResumeEducation::where('id', $request->id)->first()->toArray();
        return response()->json($eduExpArr);
    }

    /**
     * 编辑教育经历
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delEduExp(Request $request){
        $result = CollectionResumeEducation::where('id', $request->id)->delete();
        if($result){
            return response()->json(['status' => 0, 'msg' => '删除教育经历成功！']);
        }else{
            return response()->json(['status' => 1, 'msg' => '删除教育经历失败，请稍后重试！']);
        }
    }

    //项目经验------------------------------------------------------------------------------------------------------------------
    /**
     * 项目经验
     * @param addProjectExpRequest $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
     */
    public function addProjectExp(addProjectExpRequest $request){
        $input = $request->only(['resume_id', 'project_name', 'starttime', 'endtime', 'post', 'content']);
        //获取用户信息ID
        $input['addtime'] = date('Y-m-d H:i:s', time());
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        //返回插入的最后ID
        $id = CollectionResumeProjectExp::insertGetId($input);

        //获取插入后的数据
        $projectExpArr = CollectionResumeProjectExp::where('id', $id)->first()->toArray();
        $projectExpArr2 = array(
            'starttime' => substr($projectExpArr['starttime'], 0, 7),
            'post' => !empty($projectExpArr['post']) ? $projectExpArr['post'] : '无',
            'endtime' => ($projectExpArr['endtime'] == '0000-00-00') ? '至今' : substr($projectExpArr['endtime'], 0, 7)
        );

        $projectExp['arr'] = array_merge($projectExpArr, $projectExpArr2);
        $projectExp['json'] = $projectExpArr;
        return response()->json($projectExp);
    }

    /**
     * 修改项目经验
     * @param modProjectExpRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function modProjectExp(modProjectExpRequest $request){
        $input = $request->only(['resume_id', 'project_name', 'starttime', 'endtime', 'post', 'content']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        CollectionResumeProjectExp::where('id', $request->id)->update($input);

        //获取插入后的数据
        $projectExpArr = CollectionResumeProjectExp::where('id', $request->id)->first()->toArray();
        $projectExpArr2 = array(
            'starttime' => substr($projectExpArr['starttime'], 0, 7),
            'post' => !empty($projectExpArr['post']) ? $projectExpArr['post'] : '无',
            'endtime' => ($projectExpArr['endtime'] == '0000-00-00') ? '至今' : substr($projectExpArr['endtime'], 0, 7)
        );

        $projectExp['arr'] = array_merge($projectExpArr, $projectExpArr2);
        $projectExp['json'] = $projectExpArr;
        return response()->json($projectExp);
    }

    /**
     * 编辑项目经验
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function editProjectExp(Request $request){
        $projectExpArr = CollectionResumeProjectExp::where('id', $request->id)->first()->toArray();
        return response()->json($projectExpArr);
    }

    /**
     * 删除项目经验
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delProjectExp(Request $request){
        $result = CollectionResumeProjectExp::where('id', $request->id)->delete();
        if($result){
            return response()->json(['status' => 0, 'msg' => '删除项目经验成功！']);
        }else{
            return response()->json(['status' => 1, 'msg' => '删除项目经验失败，请稍后重试！']);
        }
    }
    //语言能力------------------------------------------------------------------------------------------------------------------
    /**
     * 语言能力
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
     */
    public function addLanguage(Request $request){
        //编辑不存在数组时删除数据
        $languageid = array_column(CollectionResumeLanguageSkill::where('resume_id', $request->input('resume_id'))->get()->toArray(), 'id');
        if(count($languageid) > 0){
            $id = $request->input('id.*');
            if(count($id) > 0){
                $result = array_diff($languageid, $id);
            }else{
                $result = $languageid;
            }
            if(count($result) > 0){
                foreach($result as $k => $v){
                    CollectionResumeLanguageSkill::where('id', $v)->delete();
                }
            }
        }

        //编辑存在数组时更新数据
        $input = $request->only(['resume_id', 'language', 'degree', 'level']);
        if(count($request->input('language.*')) > 0){
            $language = $request->input('language.*');
            $degree = $request->input('degree.*');
            $level = $request->input('level.*');
            $id = $request->input('id.*');
            foreach($language as $k => $v){
                if(!empty($v)){
                    $input['language'] = $v;
                    $input['degree'] = $degree[$k];
                    $input['level'] = $level[$k];
                    $input['updatetime'] = date('Y-m-d H:i:s', time());
                    CollectionResumeLanguageSkill::where('id', $id[$k])->update($input);
                }
            }
        };
        //不存在数组时添加数据
        if(count($request->input('addLanguage.*')) > 0){
            $addLanguage = $request->input('addLanguage.*');
            $addDegree = $request->input('addDegree.*');
            $addLevel = $request->input('addLevel.*');
            $input['resume_id'] = $request->input('resume_id');
            foreach($addLanguage as $k => $v){
                if(!empty($v)){
                    $input['language'] = $v;
                    $input['degree'] = $addDegree[$k];
                    $input['level'] = $addLevel[$k];
                    $input['addtime'] = date('Y-m-d H:i:s', time());
                    $input['updatetime'] = date('Y-m-d H:i:s', time());
                    CollectionResumeLanguageSkill::create($input);
                }
            }
        }

        //获取插入后的数据
        $language = CollectionResumeLanguageSkill::where('resume_id', $request->input('resume_id'))->orderBy('id')->get()->toArray();
        if(count($language) > 0){
            $languageArr = [];
            foreach($language as $v){
                $arr = array(
                    'language' => CollOption::getOptionName($v['language'], 'language'),
                    'degree' => CollOption::getOptionName($v['degree'], 'degree'),
                    'level' => CollTwoOption::getTwoOptionName($v['level'], 'language')
                );
                $languageArr[] = array_merge($v, $arr);
            }
            $languageJson['arr'] = $languageArr;
            $languageJson['json'] = $language;
            return response()->json($languageJson);
        }else{
            $languageJson['arr'] = '';
            $languageJson['json'] = '';
            return response()->json($languageJson);
        }

    }

    //技能专长------------------------------------------------------------------------------------------------------------------
    /**
     * 技能专长
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
     */
    public function addSkill(Request $request){
        //编辑不存在数组时删除数据
        $skillid = array_column(CollectionResumeSkill::where('resume_id', $request->input('resume_id'))->get()->toArray(), 'id');
        if(count($skillid) > 0){
            $id = $request->input('id.*');
            if(count($id) > 0){
                $result = array_diff($skillid, $id);
            }else{
                $result = $skillid;
            }
            if(count($result) > 0){
                foreach($result as $k => $v){
                    CollectionResumeSkill::where('id', $v)->delete();
                }
            }
        }
        //编辑存在数组时更新数据
        $input = $request->only(['resume_id', 'skillname', 'degree']);
        if(count($request->input('skillname.*')) > 0){
            $skillname = $request->input('skillname.*');
            $degree = $request->input('degree.*');
            $id = $request->input('id.*');
            foreach($skillname as $k => $v){
                if(!empty($v)){
                    $input['skillname'] = $v;
                    $input['degree'] = $degree[$k];
                    $input['updatetime'] = date('Y-m-d H:i:s', time());
                    CollectionResumeSkill::where('id', $id[$k])->update($input);
                }
            }
        };
        //不存在数组时添加数据
        if(count($request->input('addskillname.*')) > 0){
            $addskillname = $request->input('addskillname.*');
            $addDegree = $request->input('addDegree.*');
            $input['resume_id'] = $request->input('resume_id');
            foreach($addskillname as $k => $v){
                if(!empty($v)){
                    $input['skillname'] = $addskillname[$k];
                    $input['degree'] = $addDegree[$k];
                    $input['addtime'] = date('Y-m-d H:i:s', time());
                    $input['updatetime'] = date('Y-m-d H:i:s', time());
                    CollectionResumeSkill::create($input);
                }
            }
        }
        //获取插入后的数据
        $skill = CollectionResumeSkill::where('resume_id', $request->input('resume_id'))->orderBy('id')->get()->toArray();
        if(count($skill) > 0){
            $skillArr = [];
            foreach($skill as $v){
                $arr = array(
                    'degree' => CollOption::getOptionName($v['degree'], 'degree')
                );
                $skillArr[] = array_merge($v, $arr);
            }
            $skillJson['arr'] = $skillArr;
            $skillJson['json'] = $skill;
            return response()->json($skillJson);
        }else{
            $skillJson['arr'] = '';
            $skillJson['json'] = '';
            return response()->json($skillJson);
        }
    }
    //证书---------------------------------------------------------------------------------------------------------------------
    /**
     * 证书
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
     */
    public function addCertificate(Request $request){
        //编辑不存在数组时删除数据
        $certificateid = array_column(CollectionResumeCertificate::where('resume_id', $request->input('resume_id'))->get()->toArray(), 'id');
        if(count($certificateid) > 0){
            $id = $request->input('id.*');
            if(count($id) > 0){
                $result = array_diff($certificateid, $id);
            }else{
                $result = $certificateid;
            }
            if(count($result) > 0){
                foreach($result as $k => $v){
                    CollectionResumeCertificate::where('id', $v)->delete();
                }
            }
        }
        //编辑存在数组时更新数据
        $input = $request->only(['resume_id', 'certificate_name', 'gettime']);
        if(count($request->input('certificate_name.*')) > 0){
            $certificate_name = $request->input('certificate_name.*');
            $gettime = $request->input('gettime.*');
            $id = $request->input('id.*');
            foreach($certificate_name as $k => $v){
                if(!empty($v)){
                    $input['certificate_name'] = $v;
                    $input['gettime'] = $gettime[$k];
                    $input['updatetime'] = date('Y-m-d H:i:s', time());
                    CollectionResumeCertificate::where('id', $id[$k])->update($input);
                }
            }
        };
        //不存在数组时添加数据
        if(count($request->input('addcertificate_name.*')) > 0){
            $addcertificate_name = $request->input('addcertificate_name.*');
            $addGettime = $request->input('addGettime.*');
            $input['resume_id'] = $request->input('resume_id');
            foreach($addGettime as $k => $v){
                if(!empty($v)){
                    $input['certificate_name'] = $addcertificate_name[$k];
                    $input['gettime'] = $addGettime[$k];
                    $input['addtime'] = date('Y-m-d H:i:s', time());
                    $input['updatetime'] = date('Y-m-d H:i:s', time());
                    CollectionResumeCertificate::create($input);
                }
            }
        }
        //获取插入后的数据
        $certificate = CollectionResumeCertificate::where('resume_id', $request->input('resume_id'))->orderBy('id')->get()->toArray();
        if(count($certificate) > 0){
            $certificateArr = [];
            foreach($certificate as $v){
                $arr = array(
                    'gettime' => substr($v['gettime'], 0, 4)
                );
                $certificateArr[] = array_merge($v, $arr);
            }
            $certificateJson['arr'] = $certificateArr;
            $certificateJson['json'] = $certificate;
            return response()->json($certificateJson);
        }else{
            $certificateJson['arr'] = '';
            $certificateJson['json'] = '';
            return response()->json($certificateJson);
        }
    }

    //其它信息------------------------------------------------------------------------------------------------------------------
    /**
     * 其它信息
     * @param addOtherRequest $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
     */
    public function addOther(addOtherRequest $request){
        $input = $request->only(['resume_id', 'title', 'content']);
        //获取用户信息ID
        $input['addtime'] = date('Y-m-d H:i:s', time());
        $input['updatetime'] = date('Y-m-d H:i:s', time());

        if($request->title == 'zdy'){
            $input['title'] = $request->titInp;
        }else{
            $CollOption = CollOption::where('opt_id', $request->title)->where('sign', 'title')->first()->toArray();
            $input['title'] = $CollOption['opt_name'];
        }
        //返回插入的最后ID
        $id = CollectionResumeOther::insertGetId($input);

        //获取插入后的数据
        $otherArr = CollectionResumeOther::where('id', $id)->first()->toArray();
        $other['arr'] = $otherArr;
        $other['json'] = $otherArr;
        $other['newJson'] = CollectionResumeOther::where('resume_id', $request->resume_id)->get()->toArray();
        return response()->json($other);
    }

    /**
     * 修改其它信息
     * @param modOtherRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function modOther(modOtherRequest $request){
        $input = $request->only(['resume_id', 'title', 'content']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());

        if($request->title == 'zdy'){
            $input['title'] = $request->titInp;
        }else{
            $CollOption = CollOption::where('opt_id', $request->title)->where('sign', 'title')->first()->toArray();
            $input['title'] = $CollOption['opt_name'];
        }
        CollectionResumeOther::where('id', $request->id)->update($input);

        //获取插入后的数据
        $otherArr = CollectionResumeOther::where('id', $request->id)->first()->toArray();
        $other['arr'] = $otherArr;
        $other['json'] = $otherArr;
        $other['newJson'] = CollectionResumeOther::where('resume_id', $request->resume_id)->get()->toArray();
        return response()->json($other);
    }

    /**
     * 编辑其它信息
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function editOther(Request $request){
        $otherArr = CollectionResumeOther::where('id', $request->id)->first()->toArray();
        return response()->json($otherArr);
    }

    /**
     * 删除其它信息
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delOther(Request $request){
        $result = CollectionResumeOther::where('id', $request->id)->delete();
        if($result){
            return response()->json(['status' => 0, 'msg' => '删除其它信息成功！']);
        }else{
            return response()->json(['status' => 1, 'msg' => '删除其它信息失败，请稍后重试！']);
        }
    }

    /**
     * 添加正式库
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addFormalLib(Request $request){
        //获取临时数据库的手机号码
        $collectionResume = CollectionResume::select('name', 'sex', 'birthday', 'job_status', 'education', 'mobile', 'qq', 'email', 'work_year',
            'jobsort1', 'jobsort2', 'jobsort3', 'jobsort4', 'jobsort5', 'jobarea1', 'jobarea2', 'jobarea3', 'jobarea4', 'jobarea5',
            'address', 'homeaddress', 'census', 'marital', 'height', 'intentionjobs', 'expectedsalary', 'introduction', 'isexpectedsalary',
            'avatar', 'place_name', 'longitude', 'latitude')
            ->where('id', $request->resume_id)
            ->first();
        if(!empty($collectionResume) && !empty($collectionResume->mobile)){
            //判断默认简历手机号码是不是已经存在
            $resumeInfo = Resume::where('mobile', $collectionResume->mobile)->where('default', '1')->orderBy('updatetime', 'desc')->first(['id', 'mobile']);
            if(empty($resumeInfo)){
                $resumeInfo = Resume::where('mobile', $collectionResume->mobile)->where('default', '!=', '1')->orderBy('updatetime', 'desc')->first(['id', 'mobile']);
            }
            if(!empty($resumeInfo)){
                //存在更新正式库默认简历为当前时间
                Resume::where('id', $resumeInfo->id)->update(['updatetime' => date('Y-m-d H:i:s', time())]);
                //更新临时库采集数据为添加至正式库
                CollectionResume::where('id', $request->resume_id)->update(['show_type' => 3]);
                //插入简历采集更新跟踪表
                $collectionTrackResume = CollectionTrackResume::where('real_resume_id', $resumeInfo->id)->first(['id']);
                if(empty($collectionTrackResume)){
                    CollectionTrackResume::where('resume_id', $request->resume_id)->update(['real_resume_id' => $resumeInfo->id]);
                }
                return response()->json(['status' => 2, 'msg' => '当前用户简历已经存在！']);
            }else{
                //判断用户手机号码是不是已经存在
                $personalUser = PersonalUser::where('mobile', $collectionResume->mobile)->first(['uid', 'mobile']);
                if(!empty($personalUser)){
                    //获取当前更新的正式库简历ID
                    $resume = Resume::where('uid', $personalUser->uid)->where('default', 1)->first(['id']);
                    if(!empty($resume)){
                        //存在更新正式库默认简历为当前时间
                        Resume::where('uid', $personalUser->uid)->where('default', 1)->update(['updatetime' => date('Y-m-d H:i:s', time())]);
                        //更新临时库采集数据为添加至正式库
                        CollectionResume::where('id', $request->resume_id)->update(['show_type' => 3]);
                        //插入简历采集更新跟踪表
                        $collectionTrackResume = CollectionTrackResume::where('real_resume_id', $resume->id)->first(['id']);
                        if(empty($collectionTrackResume)){
                            CollectionTrackResume::where('resume_id', $request->resume_id)->update(['real_resume_id' => $resume->id]);
                        }
                        return response()->json(['status' => 2, 'msg' => '当前用户简历已经存在！']);
                    }else{
                        //插入简历信息
                        if($this->insertResumeInfo($personalUser->uid, $collectionResume, $request, '')){
                            return response()->json(['status' => 1, 'mobile' => $collectionResume->mobile, 'password' => '原网站注册的密码', 'msg' => '恭喜你，插入正式库成功！']);
                        }else{
                            return response()->json(['status' => 0, 'msg' => '插入用户数据失败!']);
                        }
                    }
                }else{
                    //插入用户信息
                    $tmp_password = rand(100000, 999999);//临时随机密码
                    $insert_uid = PersonalUser::insertGetId([
                        'mobile' => $collectionResume->mobile,
                        'email' => $collectionResume->email,
                        'password' => CustomPassword::make($tmp_password),
                        'regtime' => date('Y-m-d H:i:s', time()),
                        'updatetime' => date('Y-m-d H:i:s', time()),
                    ]);
                    //从临时采集数据移动到正式数据库
                    if($insert_uid){
                        //插入简历信息
                        if($this->insertResumeInfo($insert_uid, $collectionResume, $request, $tmp_password)){
                            return response()->json(['status' => 1, 'mobile' => $collectionResume->mobile, 'password' => $tmp_password, 'msg' => '恭喜你，插入正式库成功！']);
                        }else{
                            return response()->json(['status' => 0, 'msg' => '插入用户数据失败!']);
                        }
                    }else{
                        return response()->json(['status' => 0, 'msg' => '插入用户数据失败!']);
                    }
                }
            }
        }else{
            return response()->json(['status' => 0, 'msg' => '该简历不存在，或者手机号码无效']);
        }
    }

    /**
     * 插入正式库数据信息
     * @param $insert_uid
     * @param $collectionResume
     * @param $request
     * @param $tmp_password
     * @return \Illuminate\Http\JsonResponse
     */
    public function insertResumeInfo($insert_uid, $collectionResume, $request, $tmp_password){
        $adminUser = auth()->guard()->user();
        $collectionResumeArr = $collectionResume->toArray();
        $collectionResumeArr['uid'] = $insert_uid;
        $collectionResumeArr['default'] = 1;
        $collectionResumeArr['regtime'] = date('Y-m-d H:i:s',time());
        $collectionResumeArr['updatetime'] = date('Y-m-d H:i:s',time());
        //插入正式简历
        if($insert_resume_id = Resume::insertGetId($collectionResumeArr)){
            //工作经历
            $collectionResumeWorkExp = CollectionResumeWorkExp::select('company', 'industry', 'comkind', 'scale',
                'starttime', 'endtime', 'post', 'content', 'addtime', 'updatetime')
                ->where('resume_id', $request->resume_id)
                ->get();
            if(!empty($collectionResumeWorkExp)){
                foreach($collectionResumeWorkExp as $v){
                    $v['uid'] = $insert_uid;
                    $v['resume_id'] = $insert_resume_id;
                    ResumeWorkExp::create($v->toArray());
                }
            }
            //教育培训经历
            $collectionResumeEducation = CollectionResumeEducation::select('edu_type', 'school', 'speciality', 'education',
                'starttime', 'endtime', 'type', 'description', 'addtime', 'updatetime')
                ->where('resume_id', $request->resume_id)
                ->get();
            if(!empty($collectionResumeEducation)){
                foreach($collectionResumeEducation as $v){
                    $v['uid'] = $insert_uid;
                    $v['resume_id'] = $insert_resume_id;
                    ResumeEducationExp::create($v->toArray());
                }
            }
            //项目经验
            $collectionResumeProjectExp = CollectionResumeProjectExp::select('project_name', 'post', 'content',
                'starttime', 'endtime', 'addtime', 'updatetime')
                ->where('resume_id', $request->resume_id)
                ->get();
            if(!empty($collectionResumeProjectExp)){
                foreach($collectionResumeProjectExp as $v){
                    $v['uid'] = $insert_uid;
                    $v['resume_id'] = $insert_resume_id;
                    ResumeProjectExp::create($v->toArray());
                }
            }
            //语言能力
            $collectionResumeLanguageSkill = CollectionResumeLanguageSkill::select('language', 'degree', 'level',
                'addtime', 'updatetime')
                ->where('resume_id', $request->resume_id)
                ->get();
            if(!empty($collectionResumeLanguageSkill)){
                foreach($collectionResumeLanguageSkill as $v){
                    $v['uid'] = $insert_uid;
                    $v['resume_id'] = $insert_resume_id;
                    ResumeLanguageSkill::create($v->toArray());
                }
            }
            //技能专长
            $collectionResumeSkill = CollectionResumeSkill::select('skillname', 'degree',
                'addtime', 'updatetime')
                ->where('resume_id', $request->resume_id)
                ->get();
            if(!empty($collectionResumeSkill)){
                foreach($collectionResumeSkill as $v){
                    $v['uid'] = $insert_uid;
                    $v['resume_id'] = $insert_resume_id;
                    ResumeSkill::create($v->toArray());
                }
            }
            //技能专长
            $collectionResumeCertificate = CollectionResumeCertificate::select('certificate_name', 'gettime',
                'addtime', 'updatetime')
                ->where('resume_id', $request->resume_id)
                ->get();
            if(!empty($collectionResumeCertificate)){
                foreach($collectionResumeCertificate as $v){
                    $v['uid'] = $insert_uid;
                    $v['resume_id'] = $insert_resume_id;
                    ResumeCertificate::create($v->toArray());
                }
            }
            //项目经验
            $collectionResumeOther = CollectionResumeOther::select('title', 'content',
                'addtime', 'updatetime')
                ->where('resume_id', $request->resume_id)
                ->get();
            if(!empty($collectionResumeOther)){
                foreach($collectionResumeOther as $v){
                    $v['uid'] = $insert_uid;
                    $v['resume_id'] = $insert_resume_id;
                    ResumeOther::create($v->toArray());
                }
            }
            //更新临时库采集数据为添加至正式库
            CollectionResume::where('id', $request->resume_id)->update(['show_type' => 3]);
            //插入简历采集更新跟踪表
            CollectionTrackResume::where('resume_id', $request->resume_id)->update(['real_resume_id' => $insert_resume_id, 'admin_id' => $adminUser->id]);
            if(!empty($tmp_password)){
                //模板参数
                $smsParam = array(
                    'web_name' => Site::get('webname'),
                    'username' => (string)$collectionResume->mobile,
                    'password' => (string)$tmp_password
                );
                $smsTemplateCode = Site::get('AccountNoticeTemp');
                $smsFreeSignName = Site::get('AccountNotice');
                //发送短信通知
                Sms::codeSend($collectionResume->mobile, $smsParam, $smsTemplateCode, $smsFreeSignName);
            }
            return true;
            //-------------------------------------------------------------------------------------------------
        }else{
            return false;
        }
    }
}
